package t5.num2;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MyWindow extends JFrame{
  public MyWindow(){
      JFrame MyWindow=new JFrame();
      this.setSize(400,300);
      this.setLocationRelativeTo(null);
      this.setLayout(new FlowLayout());
      init();
      this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      this.setVisible(true);
  }
  private void init() {
      JButton btn = new JButton("点我");
      this.add(btn);
      Police police=new Police();
      btn.addActionListener(police);

  }
    class Police implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("单击事件发生了");
        }
    }
  }

